package com.phantom.reflection;

import java.lang.reflect.Method;

public class ReflectAccessMethod {
    public static void main(String[] args) throws Exception {

        Class<?> bossCls = Class.forName("com.phantom.reflection.Boss");
        Object o = bossCls.newInstance(); // 创建对象
        Method hi = bossCls.getMethod("hi", String.class);
        //Method hi2 = bossCls.getDeclaredMethod("hi", String.class);

        hi.invoke(o, "Ciel");

        Method say = bossCls.getDeclaredMethod("say", int.class, String.class, char.class);
        say.setAccessible(true);
        System.out.println(say.invoke(o, 100, "Phantom", '男'));


    }

}

class Boss {
    public int age;
    private static String name;

    public Boss() {

    }

    private static String say(int n, String s, char c) {
        return n + " " + s + " " + c;
    }

    public void hi(String s) {
        System.out.println("Hi, " + s);
    }
}
